package com.qimou.iems.service.impl;

import com.qimou.iems.entity.Department;
import com.qimou.iems.entity.PageArgs;
import com.qimou.iems.entity.PageList;
import com.qimou.iems.mapper.IDepartmentMapper;
import com.qimou.iems.service.IDepartmentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author Qimou Xie
 * @date 2018/3/17 17:25.
 **/
@Service
public class DepartmentServiceImpl implements IDepartmentService {

    @Resource
    private IDepartmentMapper departmentMapper;

    @Override
    public void save(Department department) {
        departmentMapper.insert(department);
    }

    @Override
    public void update(Department department) {
        departmentMapper.update(department);
    }

    @Override
    public PageList<Department> getDepartmentList(PageArgs pageArgs, Map<String, Object> map) {
        List<Department> departments = new ArrayList<Department>();
        int count = departmentMapper.countDepartment(map);
        if(count > 0){
            map.put("pageArgs",pageArgs);
            departments = departmentMapper.selectDepartment(map);
        }
        return new PageList<Department>(departments,count);
    }

    @Override
    public List<Department> getDepartmentByCompany(Integer companyId) {
        return departmentMapper.selectDepartmentByCompany(companyId);
    }
}
